package cn.myframe.controller;

import cn.myframe.entity.sys.SysUserEntity;
import cn.myframe.service.bus.BusCompanyService;
import cn.myframe.shiro.ShiroUtils;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * Controller公共组件
 * 
 * @author  ynz
 * @email   ynz@myframe.cn
 * @version 创建时间：2018年6月8日 上午9:40:36
 */
public abstract class AbstractController {
	@Autowired
	private BusCompanyService busCompanyService;
	protected Logger logger = LoggerFactory.getLogger(getClass());

	protected void doBefore(Map<String , Object> params) {
		// 获得当前登录用户名
		String username = getUser().getUsername();

		// 获取当前登陆用户的关联的运营商id
		Long companyId = getUser().getCompanyNo();

		if (!"admin".equals(username)) {
			// 根据companyId查询所有关联的用户名(创建人)
			List<SysUserEntity> users = busCompanyService.queryUser(companyId);
			params.put("users", users);
		}
	}
	protected SysUserEntity getUser() {
		return ShiroUtils.getUserEntity();
	}

	protected Long getUserId() {
		if(getUser() != null){
			return getUser().getUserId();
		}
		return null;
	}

	
}

 
